package com.yd.sdk.ad;

import android.app.Activity;
import android.os.Handler;
import android.util.Log;


public class AdManager {

//    private Activity _activity;
    private AdAbstractClass _adImp;
    private Handler _handler;
    public AdManager(AdAbstractClass adImp) {
        _adImp = adImp;
//        _activity = activity;
        _handler = new Handler();
    }

    public void SetTestDeviceIds(String ids)
    {
        _handler.post(new Runnable() {
            @Override
            public void run() {
                if(_adImp != null)
                    _adImp.SetTestDeviceIds(ids);
                else
                    Log.e("SDK_MAIN","_adImp为null");
            }
        });
    }

    public void SetAdIds(String bannerId, String interstitialId, String rewardId)
    {
        _handler.post(new Runnable() {
            @Override
            public void run() {
                if(_adImp != null)
                    _adImp.SetAdIds(bannerId,interstitialId,rewardId);
                else
                    Log.e("SDK_MAIN","_adImp为null");

            }
        });
    }

    public void LoadedAd(IAd.AdType adType) {
        //统一封装成主线程
        _handler.post(new Runnable() {
            @Override
            public void run() {
                if(_adImp != null)
                    _adImp.LoadedAd(adType);
                else
                    Log.e("SDK_MAIN","_adImp为null");
            }
        });
    }


    public boolean IsAdAvailable(IAd.AdType adType) {

        return _adImp.IsAdAvailable(adType);
    }


    public void ShowBanner(IAd.BannerPos pos) {

        _handler.post(new Runnable() {
            @Override
            public void run() {
                if(_adImp != null)
                    _adImp.ShowBanner(pos);
                else
                    Log.e("SDK_MAIN","_adImp为null");
            }
        });

    }


    public void ShowInterstitial() {
        _handler.post(new Runnable() {
            @Override
            public void run() {

                if(_adImp != null)_adImp.ShowInterstitial();
                else
                    Log.e("SDK_MAIN","_adImp为null");
            }
        });
    }


    public void ShowReward() {
        _handler.post(new Runnable() {
            @Override
            public void run() {
                if(_adImp != null)
                    _adImp.ShowReward();
                else
                    Log.e("SDK_MAIN","_adImp为null");
            }
        });
    }

    public void HideAd(IAd.AdType adType) {
        _handler.post(new Runnable() {
            @Override
            public void run() {
                if(_adImp != null)
                    _adImp.HideAd(adType);
                else
                    Log.e("SDK_MAIN","_adImp为null");
            }
        });
    }
}
